$(function () {
    $(".more").on({
        mouseenter: function () {
            $(".more").css({"display": "block"})
        },
        mouseleave: function () {
            $(".more").css({"display": "none"})
        }
    });
    let timer;
    $(".drop-down").on({
        mouseenter: function () {
            // 取消之前设置的延迟执行
            clearTimeout(timer);
            let boxId = $(this);
            // 设置延迟执行操作
            timer = setTimeout(function () {
                // 在延迟时间后执行操作
                if ($(boxId[0]).attr("class") !== "more drop-down") {
                    $(".more").css({"display": "none"})
                }
            }, 2000);
            // 设置延迟时间（单位为毫秒）
        },
        mouseleave: function () {
            // 取消之前设置的延迟执行
            clearTimeout(timer);

            let boxId = $(this);
            if ($(boxId[0]).attr("class") !== "more drop-down" &&
                $(boxId[0]).attr("class") !== "username options drop-down") {
                $(".more").css({"display": "none"})
            }
        }
    });
    $(".drop-down-menu").on({
        mouseenter: function () {
            $(".options-img").attr({"src": "http://localhost:8083/resource_packs/images/drop_down_color.png"})
            $(".more").css({"display": "block"})
        }, mouseleave: function () {
            $(".options-img").attr({"src": "http://localhost:8083/resource_packs/images/drop_down.png"})
        }
    });

    setInterval(function () {
        // 这里放置需要每分钟执行一次的代码
        getOrderExpirationTimeByAddressId()
    }, 60000); // 60000毫秒 = 1分钟
    getOrderExpirationTimeByAddressId()

    function getOrderExpirationTimeByAddressId() {
        // 这里放置需要每分钟执行一次的代码
        let orders = new Orders();
        orders.getOrderExpirationTimeByAddressId($(".order").attr("order-id")).then(res => {
            if (res < 0) {
                orders.updateOrderStatusByOrderId($(".order").attr("order-id")).then(res => {
                    window.location.href = "/www.xiaomi.com/shop?acccountId=" + $(".order").attr("account-id");
                }).catch(reason => {
                    console.log(reason)
                })
            } else {
                $(".timer").text(res + "分钟")
            }
        })
    }

    let removeImg = $(".remove-img");
    removeImg.on({
        mouseenter: function () {
            $(this).attr({"src": "http://localhost:8083/resource_packs/images/pop_ups_closes_red.png"})
        },
        mouseleave: function () {
            $(this).attr({"src": "http://localhost:8083/resource_packs/images/pop_ups_closes.png"})
        }
    });
    removeImg.on("click", function () {
        $($(".hint-remove")).css({
            "display": "none"
        })

    })
    $(".alipay-payment").on("click", function () {
        let pay = new Pay();
        pay.alipayPaymentQRCode($(".order").attr("order-price"),
            $(".order").attr("order-id"),
            $(".order").attr("account-id"),
            $(".order").attr("information-id")).then(res => {
            console.log(res)
            $(".pay-body-window").html(res)
        })
    })

})